package com.zlzlib.libuimodel.model;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.Observer;

import com.zlzlib.librx.TUtil;
import com.zlzlib.libuimodel.bean.SourceData;

import io.reactivex.rxjava3.disposables.Disposable;


/**
 * Created by zlz on 2019/8/29.
 * 页面数据交互类  数据逻辑处理
 */
public class BaseViewModel<T extends RxDataModel> extends AndroidViewModel {

    protected T mDataModel;

    public BaseViewModel(@NonNull Application application) {
        super(application);
        mDataModel = TUtil.getNewInstance(this, 0);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        mDataModel.unDisposable();
    }


    public void addPageDataObserve(LifecycleOwner owner, String key, Observer<? super SourceData> observer) {
        mDataModel.addPageDataObserve(owner, key, observer);
    }
    public void addPageLoadingObserve(LifecycleOwner owner, String key, Observer<? super SourceData> observer) {
        mDataModel.addPageLoadingObserve(owner, key, observer);
    }
    public void addPageTipObserve(LifecycleOwner owner, String key, Observer<? super SourceData> observer) {
        mDataModel.addPageTipObserve(owner, key, observer);
    }

    public void addDisposable(Disposable disposable) {
        mDataModel.addDisposable(disposable);
    }

    public void cancelDisposable(Disposable disposable) {
        mDataModel.cancelDisposable(disposable);
    }
}
